import Vue from 'vue';
import VueRouter from 'vue-router';
// import routes from "./routes.js";
// import NProgress from "nprogress";
// import "nprogress/nprogress.css";

Vue.use(VueRouter)

export const constantRoutes = [
	{
		path: '/401',
		component: () => import('@/views/error/401'),
		hidden: true
	},
	{
		path: '/404',
		component: () => import('@/views/error/404'),
		hidden: true
	}
];

export const constantRoutes1 = [
	{
		path: "/",
		name: "Root",
		component: () => import('@/components/layout/BasicLayout.vue'),
		redirect: { path: "/works" },
		"meta": {
			"title": "项目案例",
			"icon": null,
			"noCache": false,
			"link": null
		},
		children: [
			{
				"name": "Works",
				"path": "/works",
				"hidden": false,
				component: () => import('@/views/work/index.vue'),
				query: {cat_id: 'areaFlag'},
				"meta": {
					"title": "户型",
					"icon": null,
					"noCache": false,
					"link": null
				}
			},
			{
				"name": "Works",
				"path": "/works",
				"hidden": false,
				component: () => import('@/views/work/index.vue'),
				query: {cat_id: 'familyFlag'},
				"meta": {
					"title": "常住人口",
					"icon": null,
					"noCache": false,
					"link": null
				}
			},
			{
				"name": "Works",
				"path": "/works",
				"hidden": false,
				component: () => import('@/views/work/index.vue'),
				query: {cat_id: 'styleFlag'},
				"meta": {
					"title": "风格",
					"icon": null,
					"noCache": false,
					"link": null
				}
			},
			{
				"name": "Works",
				"path": "/works",
				"hidden": false,
				component: () => import('@/views/work/index.vue'),
				query: {cat_id: 'typeFlag'},
				"meta": {
					"title": "原始状态",
					"icon": null,
					"noCache": false,
					"link": null
				}
			},
			// {
			// 	"name": "Works",
			// 	"path": "/works",
			// 	"hidden": false,
			// 	component: () => import('@/views/work/index.vue'),
			// 	query: {cat_id: 'cityFlag'},
			// 	"meta": {
			// 		"title": "城市",
			// 		"icon": null,
			// 		"noCache": false,
			// 		"link": null
			// 	}
			// },
			{
				"name": "Works",
				"path": "/works",
				"hidden": false,
				component: () => import('@/views/work/index.vue'),
				query: {cat_id: 'yearFlag'},
				"meta": {
					"title": "年度",
					"icon": null,
					"noCache": false,
					"link": null
				}
			},
			{
				path: "/works/detail",
				name: "WorkDetail",
				component: () => import('@/views/workDetail/index.vue'),
				meta: {
					title: "作品详情/Works"
				}
			}
		]
	},
	{
		"path": "/",
		"hidden": false,
		component: () => import('@/components/layout/BasicLayout.vue'),
		"children": [
			{
				"name": "Team",
				"path": "team",
				"hidden": false,
				"component": () => import('@/views/team/index'),
				"meta": {
					"title": "小隐团队",
					"icon": "1873028501639053314",
					"noCache": false,
					"link": null
				}
			}
		]
	},
	{
		"path": "/",
		"hidden": false,
		component: () => import('@/components/layout/BasicLayout.vue'),
		"children": [
			{
				"name": "About",
				"path": "about",
				"hidden": false,
				"component": () => import('@/views/about/index'),
				"meta": {
					"title": "关于小隐",
					"icon": "1873028550662078466",
					"noCache": false,
					"link": null
				}
			}
		]
	},
	{
		"path": "/",
		"hidden": false,
		component: () => import('@/components/layout/BasicLayout.vue'),
		"children": [
			{
				"name": "Contact",
				"path": "contact",
				"hidden": false,
				"component": () => import('@/views/contact/index'),
				"meta": {
					"title": "联系方式",
					"icon": "1873028550662078466",
					"noCache": false,
					"link": null
				}
			}
		]
	}
];

const dynamicRoutes = [
    {
        "name": "Works",
        "path": "/",
        "hidden": false,
        "redirect": {
            "path": "/works"
        },
        "alwaysShow": true,
        "meta": {
            "title": "项目案例",
            "titleEn": "Projects",
            "icon": "1876894344554721281",
            "noCache": false,
            "link": null
        },
        "children": [
            {
                "name": "/works",
                "path": "/works",
                "hidden": false,
                "query": {
                    "cat_id": "areaFlag"
                },
                "meta": {
                    "title": "面积",
                    "titleEn": "area",
                    "icon": null,
                    "noCache": false,
                    "link": null
                }
            },
            {
                "name": "/works",
                "path": "/works",
                "hidden": false,
                "query": {
                    "cat_id": "familyFlag"
                },
                "meta": {
                    "title": "家庭成员",
                    "titleEn": "family members",
                    "icon": null,
                    "noCache": false,
                    "link": null
                }
            },
            {
                "name": "/works",
                "path": "/works",
                "hidden": false,
                "query": {
                    "cat_id": "styleFlag"
                },
                "meta": {
                    "title": "风格",
                    "titleEn": "style",
                    "icon": null,
                    "noCache": false,
                    "link": null
                }
            },
            {
                "name": "/works",
                "path": "/works",
                "hidden": false,
                "query": {
                    "cat_id": "typeFlag"
                },
                "meta": {
                    "title": "类型",
                    "titleEn": "type",
                    "icon": null,
                    "noCache": false,
                    "link": null
                }
            },
            {
                "name": "/works",
                "path": "/works",
                "hidden": false,
                "query": {
                    "cat_id": "yearFlag"
                },
                "meta": {
                    "title": "年度",
                    "titleEn": "year",
                    "icon": "",
                    "noCache": false,
                    "link": null
                }
            }
        ]
    },
    {
        "path": "/",
        "hidden": false,
        "children": [
            {
                "name": "/team",
                "path": "/team",
                "hidden": false,
                "meta": {
                    "title": "小隐团队",
                    "titleEn": "Team",
                    "icon": "1873028501639053314",
                    "noCache": false,
                    "link": null
                }
            }
        ]
    },
    {
        "path": "/",
        "hidden": false,
        "children": [
            {
                "name": "/about",
                "path": "/about",
                "hidden": false,
                "meta": {
                    "title": "关于小隐",
                    "titleEn": "About",
                    "icon": "",
                    "noCache": false,
                    "link": null
                }
            }
        ]
    },
    {
        "path": "/",
        "hidden": false,
        "children": [
            {
                "name": "/contact",
                "path": "/contact",
                "hidden": false,
                "meta": {
                    "title": "联系方式",
                    "titleEn": "Contact",
                    "icon": "1873028550662078466",
                    "noCache": false,
                    "link": null
                }
            }
        ]
    }
]

export const detailRoute = [
	{
        "path": "/",
        "hidden": false,
		component: () => import('@/components/layout/BasicLayout.vue'),
        "children": [
            {
                "name": "WorkDetail",
                "path": "/works/detail",
                "hidden": false,
                "meta": {
                    "title": "作品详情/Works",
                    "titleEn": "worksDetail",
                    "icon": "",
                    "noCache": false,
                    "link": null
                }
            }
        ]
    }
]

export const asyncRoutes = [];

const createRouter = () => new VueRouter({
	mode: "hash", // history 在生产环境中，history 模式有一个比较大的问题，当手动刷新时，会报404错误
	// base: process.env.BASE_URL,
	routes: constantRoutes,
	scrollBehavior(to) {
		if (to.hash) {
			return {
				selector: to.hash
			};
		}
		return { x: 0, y: 0 };
	}
});

const router = createRouter();

export const resetRouter = () => {
	const newRouter = createRouter();
	router.matcher = newRouter.matcher; // reset router
}

// router.firstInit = false;
// router.beforeEach(async (to, from, next) => {
// 	NProgress.start();
// 	if (to.meta.title) {
// 		document.title = to.meta.title;
// 	}
// 	next();
// });
// router.afterEach((to, from) => {
// 	NProgress.done();
// });

export default router;